#include <stdbool.h>  /* C99 only */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 10
void generate_random_walk(char walk[N][N]);
void print_array(char walk[N][N]);
int main(void)
{
    char maze[N][N];
    generate_random_walk(maze);
    print_array(maze);
    return 0;
}
void generate_random_walk(char walk[N][N]) {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++)
            walk[i][j] = '.';
    }

    srand((unsigned) time(NULL));
    walk[0][0] = 'A';
    for (char ch = 'A', i = 0, j = 0; ch < 'Z';) {
        int choice[5] = {0, -1, -1, -1, -1};
        if ((i - 1 >= 0) && (walk[i-1][j] == '.')) {
            choice[0]++;
            choice[choice[0]] = 1;  /* 上 */
        }
        if ((j + 1 < 10) && (walk[i][j+1] == '.')) {
            choice[0]++;
            choice[choice[0]] = 2;  /* 右 */
        }
        if ((i + 1 < 10) && (walk[i+1][j] == '.')) {
            choice[0]++;
            choice[choice[0]] = 3;  /* 下 */
        }
        if ((j - 1 >= 0) && (walk[i][j-1] == '.')) {
            choice[0]++;
            choice[choice[0]] = 4;  /* 左 */
        }
        if (choice[0] == 0) {
            break;
        }

        switch (choice[rand() % choice[0] + 1])
        {
        case 1:
            walk[--i][j] = ++ch;
            break;
        case 2:
            walk[i][++j] = ++ch;
            break;
        case 3:
            walk[++i][j] = ++ch;
            break;
        case 4:
            walk[i][--j] = ++ch;
            break;
        }
    }
}
void print_array(char walk[N][N]) {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (j != 0)
                printf(" ");
            printf("%c", walk[i][j]);
        }
        printf("\n");
    }
}